import { GlobalHelp, PSModelServiceImpl } from "@ibiz/dynamic-model-api";
import { SandboxService } from "./sandbox/sandbox-service";
import { StudioToolModelServiceSandBox } from "./sandbox/studio-tool";

/**
 * 获取模型服务实例
 *
 * @author chitanda
 * @date 2022-05-23 15:05:54
 * @export
 * @param {KeyVal} [param]
 * @return {*}  {Promise<PSModelServiceImpl>}
 */
export function GetModelService(param?: KeyVal): Promise<PSModelServiceImpl> {
  if (param) {
    if (param.srfapplicationtag) {
      return StudioToolModelServiceSandBox.getInstance().getModelService(param.srfapplicationtag);
    }
    if (param.srfsandboxtag) {
      return SandboxService.getInstance().getSandBoxInstance(param.srfsandboxtag).getModelService(param);
    }
    if (param.instTag && param.instTag2) {
      return GlobalHelp.getModelServiceByTag(param.instTag, param.instTag2);
    }
    return GlobalHelp.getModelService(param.srfdynainstid);
  }
  return GlobalHelp.getModelService();
}
